package com.wd.buycar.view.activity

import androidx.activity.viewModels
import androidx.lifecycle.Observer
import androidx.recyclerview.widget.LinearLayoutManager
import com.wd.buycar.databinding.ActivityClooseCarBinding
import com.wd.buycar.view.adapter.BuynewcarClooseAdapter
import com.wd.common.base.BaseActivity
import com.wd.common.viewmodel.MyViewModel

class NewCarClooseCarActivity : BaseActivity<ActivityClooseCarBinding, Any?>() {
    val viewmodel: MyViewModel by viewModels()
    private var adapter: BuynewcarClooseAdapter? = null
    override fun getViewBinding(): ActivityClooseCarBinding =
        ActivityClooseCarBinding.inflate(layoutInflater)

    override fun initData() {

        val id = this.intent.getIntExtra("id", 0)

        viewmodel.buy_newcarClooseList(id, 1, 5)
        viewmodel.buy_newcarClooseListLiveData.observe(this, Observer {
            adapter = this?.let { it1 -> BuynewcarClooseAdapter(it1, it.result) }
            binding.buyNewcarClooserecy.layoutManager = LinearLayoutManager(this)
            binding.buyNewcarClooserecy.adapter = adapter
        })
        binding.buyNewcarCloosetext.setOnClickListener {
            finish()
        }
    }
}